package com.androidx.p013lv.mine.fragment;

import android.os.Bundle;
import android.view.View;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.event.AttentionEvent;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.view.StatusControlLayout;
import com.androidx.p013lv.mine.C1207R;
import com.androidx.p013lv.mine.adapter.MineAttentionAdapter;
import com.androidx.p013lv.mine.bean.AttentionBean;
import com.androidx.p013lv.mine.databinding.FragmentMineAttentionBinding;
import com.androidx.p013lv.mine.model.MineAttentionModel;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import java.util.List;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/* renamed from: com.androidx.lv.mine.fragment.MineAttentionFragment */
public class MineAttentionFragment extends LazyFragment<FragmentMineAttentionBinding> implements OnRefreshLoadMoreListener, ItemClickListener {
    private MineAttentionAdapter adapter;
    private MineAttentionModel model;
    private int page = 1;

    public static MineAttentionFragment newInstance() {
        Bundle bundle = new Bundle();
        MineAttentionFragment mineAttentionFragment = new MineAttentionFragment();
        mineAttentionFragment.setArguments(bundle);
        return mineAttentionFragment;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return C1207R.C1212layout.fragment_mine_attention;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        EventBus.getDefault().register(this);
        this.model = (MineAttentionModel) new ViewModelProvider(this).get(MineAttentionModel.class);
        MineAttentionAdapter mineAttentionAdapter = new MineAttentionAdapter(getContext());
        this.adapter = mineAttentionAdapter;
        mineAttentionAdapter.setItemListener(this);
        ((FragmentMineAttentionBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getContext()));
        ((FragmentMineAttentionBinding) this.binding).recycler.setAdapter(this.adapter);
        ((FragmentMineAttentionBinding) this.binding).refresh.setOnRefreshListener(this);
        ((FragmentMineAttentionBinding) this.binding).refresh.setOnLoadMoreListener(this);
        ((FragmentMineAttentionBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.fragment.MineAttentionFragment.View$OnClickListenerC13161 */

            public void onClick(View view) {
                MineAttentionFragment.this.page = 1;
                ((FragmentMineAttentionBinding) MineAttentionFragment.this.binding).setStatus(2);
                MineAttentionFragment.this.model.getAttentionList(MineAttentionFragment.this.page);
            }
        });
        this.model.dataAttention().observe(this, new Observer<BaseRes<AttentionBean>>() {
            /* class com.androidx.p013lv.mine.fragment.MineAttentionFragment.C13172 */

            public void onChanged(BaseRes<AttentionBean> baseRes) {
                MineAttentionFragment.this.hideLoading();
                if (baseRes.getCode() == 200) {
                    AttentionBean data = baseRes.getData();
                    if (MineAttentionFragment.this.page == 1) {
                        if (data == null || data.getList() == null || data.getList().size() == 0) {
                            ((FragmentMineAttentionBinding) MineAttentionFragment.this.binding).setStatus(4);
                            return;
                        }
                        List<AttentionBean.DataBean> list = data.getList();
                        MineAttentionFragment.this.adapter.setDomain(data.getDomain());
                        MineAttentionFragment.this.adapter.setData(list);
                        if (list.size() < 30) {
                            ((FragmentMineAttentionBinding) MineAttentionFragment.this.binding).setStatusRefresh(2);
                        }
                    } else if (data == null || data.getList() == null || data.getList().size() == 0) {
                        ((FragmentMineAttentionBinding) MineAttentionFragment.this.binding).setStatusRefresh(2);
                    } else {
                        List<AttentionBean.DataBean> list2 = data.getList();
                        int total = data.getTotal();
                        MineAttentionFragment.this.adapter.setDatasInEnd(list2);
                        if (total < 30) {
                            ((FragmentMineAttentionBinding) MineAttentionFragment.this.binding).setStatusRefresh(2);
                        }
                    }
                } else if (MineAttentionFragment.this.page == 1) {
                    ((FragmentMineAttentionBinding) MineAttentionFragment.this.binding).setStatus(1);
                } else {
                    ToastUtils.getInstance().showWrong(baseRes.getMsg());
                }
            }
        });
        ((FragmentMineAttentionBinding) this.binding).setStatus(2);
        this.model.getAttentionList(this.page);
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        int i = this.page + 1;
        this.page = i;
        this.model.getAttentionList(i);
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.page = 1;
        this.model.getAttentionList(1);
    }

    public void hideLoading() {
        ((FragmentMineAttentionBinding) this.binding).setStatus(0);
        ((FragmentMineAttentionBinding) this.binding).setStatusRefresh(1);
    }

    public static void showStatusView(StatusControlLayout statusControlLayout, int i) {
        statusControlLayout.showStatusView(i);
    }

    public static void refreshStatus(SmartRefreshLayout smartRefreshLayout, int i) {
        if (i == 1) {
            smartRefreshLayout.finishLoadMore();
            smartRefreshLayout.finishRefresh();
        }
        if (i == 2) {
            smartRefreshLayout.finishLoadMoreWithNoMoreData();
        }
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        ARouter.getInstance().build(Constance.STAR_INFO_ACTIVITY).withInt("type", ((AttentionBean.DataBean) this.adapter.getDataInPosition(i)).getContentId()).withString(Key.TXT, "關注").navigation();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onGetMessage(AttentionEvent attentionEvent) {
        MineAttentionAdapter mineAttentionAdapter = this.adapter;
        if (!(mineAttentionAdapter == null || mineAttentionAdapter.getData() == null || this.adapter.getData().size() == 0)) {
            for (int i = 0; i < this.adapter.getItemCount(); i++) {
                if (attentionEvent.getContentId() == ((AttentionBean.DataBean) this.adapter.getDataInPosition(i)).getContentId()) {
                    this.adapter.getData().remove(i);
                    this.adapter.notifyDataSetChanged();
                    return;
                }
            }
        }
    }

    @Override // androidx.fragment.app.Fragment, com.androidx.p013lv.base.p015ui.LazyFragment
    public void onDestroyView() {
        super.onDestroyView();
        EventBus.getDefault().unregister(this);
        MineAttentionModel mineAttentionModel = this.model;
        if (mineAttentionModel != null) {
            mineAttentionModel.cancelHttp();
        }
    }
}
